﻿using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO.IsolatedStorage;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace WP7Guide
{
    using System.Collections.Generic;
    using System.Collections.ObjectModel;

    public class SettingsViewModel : INotifyPropertyChanged
    {
        private string _dreamboxHost = "sample.dyndns.de:80";
        public string DreamboxHost
        {
            get
            {
                return _dreamboxHost;
            }
            set
            {
                if (value != _dreamboxHost)
                {
                    _dreamboxHost = value;
                    NotifyPropertyChanged("DreamboxHost");
                }
            }
        }

        private int _maxChannels = 3;
        public int MaxBouquets
        {
            get
            {
                return _maxChannels;
            }
            set
            {
                if (value != _maxChannels)
                {
                    _maxChannels = value;
                    NotifyPropertyChanged("MaxBouquets");
                }
            }
        }

        private int _daysToLoad = 1;
        public int DaysToLoad
        {
            get
            {
                return _daysToLoad;
            }
            set
            {
                if (value != _daysToLoad)
                {
                    
                        _daysToLoad = value;
                        NotifyPropertyChanged("DaysToLoad");   
                    
                }
            }
        }

        private TimeSpan _updateInterval = TimeSpan.FromDays(1);
        public TimeSpan UpdateInterval
        {
            get { return _updateInterval; }
            set { _updateInterval = value; NotifyPropertyChanged("UpdateInterval"); }
        }

        private bool _firstStart=true;
        public bool FirstStart
        {
            get { return _firstStart; }
            set { _firstStart = value; }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public void SaveData()
        {
            FirstStart = false;
            if (IsolatedStorageSettings.ApplicationSettings.Contains("settings"))
            {
                IsolatedStorageSettings.ApplicationSettings.Remove("settings");
            }
            IsolatedStorageSettings.ApplicationSettings.Add("settings", this);
            IsolatedStorageSettings.ApplicationSettings.Save();
        }
    }
}